package com.example.testdemo;


import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * 锁升级机制
 *     读锁尝试升级为写锁
 *     结论：写锁不能升级为读锁
 */
public class DemoReadWriteLock {

    public static void main(String[] args) {

        ReadWriteLock lock=new ReentrantReadWriteLock();

        Lock  rlock= lock.readLock();
        Lock  wlock=lock.writeLock();


        rlock.lock();
        System.out.println("==========rlock begin");

        wlock.lock();
        System.out.println("=========wlock begin");

        wlock.unlock();
        rlock.unlock();


    }
}
